package utils
{
	import flash.events.Event;

	import mx.managers.PopUpManager;

	import view.WindowWaiting;

	/**
	 * 等待组件
	 * setLabel(str:String, value:int=-1)说明，进度1-100
	 * @author Administrator
	 *
	 */
	public class WaitingUtils
	{

		static private var _waiting:WindowWaiting;

		static public function get window():WindowWaiting
		{
			return _waiting||=new WindowWaiting();
		}

		static public function openWaitingWindow():WindowWaiting
		{
			_waiting||=new WindowWaiting();
			if (_waiting.isPopUp == false && AppUtils.app)
			{
				PopUpManager.addPopUp(_waiting, AppUtils.app, true);
				PopUpManager.centerPopUp(_waiting);
				_waiting.isPopUp=true;
				AppUtils.app.addEventListener(Event.RESIZE, RESIZE);
			}
			return _waiting;
		}

		static private function RESIZE(e:Event):void
		{
			if (_waiting && _waiting.parent)
			{
				PopUpManager.centerPopUp(_waiting);
			}
		}

		static public function closeWaitingWindow():void
		{
			if (_waiting && _waiting.isPopUp)
			{
				PopUpManager.removePopUp(_waiting);
				AppUtils.app.removeEventListener(Event.RESIZE, RESIZE);
			}
		}
	}
}
